from django.db import models


# Create your models here.

def upload_home_back(model, filename):
    return 'home/static/home/img/home_back/%s' % (filename)
def upload_fea_back(model, filename):
    return 'home/static/home/img/home_fea/%s' % (filename)
def upload_sec_back(model, filename):
    return 'home/static/home/img/home_sec/%s' % (filename)
class Home(models.Model):
    title = models.CharField(u'标题', max_length=16)
    home_title = models.CharField(u'中间的标题', max_length=16)
    home_brief = models.CharField(u'中间的简介', max_length=64)
    home_back = models.ImageField(u'首页的背景图', upload_to=upload_home_back)

    class Meta:
        verbose_name = '主页'
        verbose_name_plural = '主页'

    def save(self, *args, **kwargs):
        if Home.objects.count() <= 1:
            super(Home, self).save(*args, **kwargs)
        if Home.objects.count() > 1:
            super(Home, self).delete(*args, **kwargs)

    def __str__(self):
        return "主页配置"

class Feature(models.Model):
    title = models.CharField(u'标题', max_length=16)
    feature_title = models.CharField(u'中间的简介', max_length=32)
    feature_back = models.ImageField(u'卡牌的图片', upload_to=upload_fea_back)

    class Meta:
        verbose_name = '团队'
        verbose_name_plural = '团队'

    def save(self, *args, **kwargs):
        if Feature.objects.count() <= 8:
            super(Feature, self).save(*args, **kwargs)
        if Feature.objects.count() > 8:
            super(Feature, self).delete(*args, **kwargs)

    def __str__(self):
        return self.title

#
class Services(models.Model):
    title = models.CharField(u'标题', max_length=16)
    services_title = models.CharField(u'中间的简介', max_length=128)


    class Meta:
        verbose_name = '服务'
        verbose_name_plural = '服务'

    def save(self, *args, **kwargs):
        if Services.objects.count() <= 4:
            super(Services, self).save(*args, **kwargs)
        if Services.objects.count() > 4:
            super(Services, self).delete(*args, **kwargs)

    def __str__(self):
        return self.title

class Section(models.Model):
    title = models.CharField(u'标题', max_length=16)
    section_back = models.ImageField(u'图片', upload_to=upload_sec_back)

    class Meta:
        verbose_name = '展示'
        verbose_name_plural = '展示'

    def __str__(self):
        return self.title

class Footer(models.Model):
    title=models.CharField(u'标题',max_length=32)
    year=models.IntegerField(u'年份')
    icp=models.CharField(u'ICP',max_length=32)
    beian=models.CharField(u'备案号',max_length=64)

    class Meta:
        verbose_name = '关于'
        verbose_name_plural = '关于'
    def save(self, *args, **kwargs):
        if Footer.objects.count() <= 1:
            super(Footer, self).save(*args, **kwargs)
        if Footer.objects.count() > 1:
            super(Footer, self).delete(*args, **kwargs)

    def __str__(self):
        return self.title
